﻿using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zhaoxi.PrismLesson.Base;

namespace Zhaoxi.PrismLesson.ViewModels
{
    class MainViewModel : BindableBase
    {
        // 通知属性
        private int _value;

        public int Value
        {
            get { return _value; }
            set { SetProperty<int>(ref _value, value); }
        }

        public DelegateCommand ButtonCommand { get; set; }

        public MainViewModel(IEventAggregator eventAggregator)
        {
            ButtonCommand = new DelegateCommand(() =>
            {
                eventAggregator.GetEvent<Message>().Publish("Hello");
            });

            // 事件总线对象的订阅
            eventAggregator.GetEvent<Message>().Subscribe(new Action<string>(OnMessage));
        }

        private void OnMessage(string arg)
        {

        }
    }
}
